route.js 768 B

1234567891011121314151617181920212223242526272829303132
  1. import { NextResponse } from "next/server";
  2. import { listDays } from "@/lib/storage";
  3. export async function GET(request, ctx) {
  4. const { branch, year, month } = await ctx.params;
  5. console.log("[/api/branches/[branch]/[year]/[month]/days] params:", {
  6. branch,
  7. year,
  8. month,
  9. });
  10. if (!branch || !year || !month) {
  11. return NextResponse.json(
  12. { error: "branch, year oder month fehlt" },
  13. { status: 400 }
  14. );
  15. }
  16. try {
  17. const days = await listDays(branch, year, month);
  18. return NextResponse.json({ branch, year, month, days });
  19. } catch (error) {
  20. console.error(
  21. "[/api/branches/[branch]/[year]/[month]/days] Fehler:",
  22. error
  23. );
  24. return NextResponse.json(
  25. { error: "Fehler beim Lesen der Tage: " + error.message },
  26. { status: 500 }
  27. );
  28. }
  29. }